<?php
/**
 * 管理员后台控制器
 * 
 * @version $Id: Exchange.php 282 2012-04-27 02:43:07Z linsir123 $
 */
class controllerExchange extends AdminController 
{
	/**
	 * 申请支付列表
	 */
	public function actionIndex()
	{
		$show = 15;
		
		///
		$params = array();
		$params['state'] = intval($_POST['state']);
		if (isset($_POST['uid'])) 
			$params['uid'] = intval($_POST['uid']);
			
		///
		$ma = MA::exchange();
		if ($count = $ma->getListCount($params)) {
			$page = $this->pagination($show, $count, 'exchange/index');
			$list = $ma->getList(($page-1)*$show, $show, $params);
			View::assign('list', $list);
		}
		
		///
		View::display('user/exchange_list');
		View::assignSet(array(
			'title' => '支付列表',
			'states' => $ma->states
		));
	}
	
	/**
	 * 支付确认
	 */
	public function actionPay()
	{
		$ma = MA::exchange();
		$id = intval($_GET['id']);
		$exchage = $ma->getById($id);
		if (empty($exchage) || $exchage['state'] != 0) 
			$this->r('exchange');
			
		///
		$account = MA::user()->getAccountByUid($exchage['uid']);
		if (Request::isPost()) {
			$message = $ma->pay($exchage, $account);
			$this->tipMsg($message, 1, 0, 'exchange');
			
		} else {
			View::display('user/exchange_pay');
			View::assignSet(array(
				'title' => '支付确认',
				'exchage' => $exchage,
				'account' => $account,
			));
		}
	}
}
